/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com;

import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author alrz
 */
public class Zone extends JPanel
{
    private ArrayList<Figure> figuras;
    private static int size = 2;
    
    public Zone()
    {
        super();
        this.figuras = new ArrayList<Figure>();
        this.setLayout(null);
        this.size = 3;
    }
    
    @Override
    public void paint(Graphics g)
    {
        for(int y=0; y<size; y++)
        {
            for( int x = 0 ; x < size ; x++)
            {
                g.drawRect((x+1)*100, (y+1)*100, 100, 100);
            }
         }
        
        for(int y=0; y<size; y++)
        {
            for( int x = 0 ; x < size ; x++)
            {
                g.drawRect(((this.size)+1)*100+(x+1)*100, (y+1)*100, 100, 100);
            }
         }
    }
    
    public void createGame()
    {
        Figure matriz[][] = new Figure[this.size][this.size];
        Random s = new Random();
        for(int i = 0 ; i< size; i++)
        {
            for(int j = 0 ; j < size  ; j++)
            {
                Figure figuraTemp = new Figure(s.nextInt(10),s.nextInt(10),s.nextInt(10),s.nextInt(10));
                matriz[i][j] = figuraTemp;
                if(j>0)
                {
                    matriz[i][j].setLeft(matriz[i][j-1].getRight());
                }
                if(i>0)
                {
                    matriz[i][j].setUp(matriz[i-1][j].getDown());
                }
            }
        }
        int nAzar = s.nextInt(size)+1;
        int i = 0;
        int x1,y1,x2,y2;
        
        while(i<nAzar)
        {
            x1 = s.nextInt(size);
            y1 = s.nextInt(size);
            x2 = s.nextInt(size);
            y2 = s.nextInt(size);
            Figure temp = matriz[x1][y1];
            matriz[x1][y1] = matriz[x2][y2];
            matriz[x2][y2] = temp;  
            i++;
        }
        this.figuras = new ArrayList<Figure>();
        
        for(int x = 0; x<size; x++)
        {
            for(int y = 0; y<size; y++)
            {
                super.add(matriz[x][y]);
                matriz[x][y].setBounds((x)*100+500, (y)*100 +100, 100,100);
                this.figuras.add(matriz[x][y]);
            }
        }   
    }
}
